#pragma once

#include "Math/Vec2.h"
#include "Math/IntPoint.h"
#include "Math/MathBase.h"
#include "Containers/Optional.h"
#include "Rect.m.h"

RSTRUCT()
struct WHENGINE_API SRect
{
    ROBJECT

    SRect();
    
    SRect(SVec2 Min,SVec2 Extent);

    SRect(Float MinX,Float MinY,Float MaxX,Float MaxY);

    RFIELD()
    SVec2 Min;

    RFIELD() 
    SVec2 Extent;

    Float GetMaxX() const;

    Float GetMaxY() const;

    static SRect Zero;

    TOptional<SRect> Intersect(const SRect& Other) const;

    bool IsPointIn(const SVec2 & InPoint) const;

    /// @brief 
    /// @param InPoint 
    /// @return find closet point in rect
    SVec2 Clamp(const SVec2& InPoint) const;

    SIntPoint Clamp(const SIntPoint& InPoint) const;

    bool operator ==(const SRect& Other)const
    {
        return Min==Other.Min && Extent==Other.Extent;
    }
};
